<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link
      rel="stylesheet"
      href="./general-styles-of-descendant-components.css"
    />
  </head>
  <body>
    <div id="root"></div>
    <script src="https://cdn.bootcdn.net/ajax/libs/react/17.0.1/umd/react.development.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/react-dom/17.0.1/umd/react-dom.development.min.js"></script>
    <script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
    <script type="text/babel">
      const { Component } = React;
      const { unmountComponentAtNode } = ReactDOM;
      class Parent extends Component {
        constructor() {
          super();
          this.state = { carName: "保时捷" };
          console.log("Parent---constructor1");
        }
        handleChangeCar = () => {
          this.setState({
            carName: "徕卡",
          });
        };
        handleUmount = () => {
          unmountComponentAtNode(document.getElementById("root"));
        };
        forceUpdates = () => {
          this.forceUpdate();
        };
        static getDerivedStateFromProps(nextProps, prevState) {
          console.log("Parent---getDerivedStateFromProps3");
          console.log(nextProps, prevState);
          return null;
        }
        componentDidMount() {
          console.log("Parent---componentDidMount4");
        }
        getSnapshotBeforeUpdate() {
          return "131321312";
        }
        componentDidUpdate(prevProps, prevState, snapshotValue) {
          console.log(
            "componentDidUpdate",
            prevProps,
            prevState,
            snapshotValue
          );
        }

        shouldComponentUpdate(nextProps, nextState) {
          console.log("Parent---shouldComponentUpdate");
          return true;
        }

        componentWillUnmount() {
          console.log("Parent---componentWillUnmount5");
        }
        render() {
          console.log("render3");
          return (
            <div className="Parent">
              <h3>
                我是Parent组件: <span>{this.state.carName}</span>
              </h3>
              <button onClick={this.handleChangeCar}>换车</button>
              <button onClick={this.handleUmount}>卸载</button>
              <button onClick={this.forceUpdates}>强制更新</button>
            </div>
          );
        }
      }
      const App = (
        <div>
          <Parent carName="卡宴"></Parent>
        </div>
      );
      ReactDOM.render(App, document.getElementById("root"));
    </script>
  </body>
</html>
